#ifndef TRACKING_THREAD_HXX
#define TRACKING_THREAD_HXX
#include <QThread>

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>

class Sequence;
class FramePool;

enum TrackingStatus
{
	TR_STATUS_UNKOWN,
	TR_STATUS_TRACKING,
	TR_STATUS_STOPPING,
	TR_STATUS_STOPPED
};

class TrackingThread : public QThread
{
	Q_OBJECT
public:
	TrackingThread();
	~TrackingThread();

	virtual void initialize();

	void stop();

    inline void setModel(Sequence* model) { _model = model; }

	inline void setInputFramePool(FramePool* pool) { _inputPool = pool; }
	inline void setOutputFramePool(FramePool* pool) { _outputPool = pool; }

	void startTrack();
	void stopTrack();

	inline void setStopTracking(bool flag) { _stopTrackFlag = flag; }
	inline bool isStopTracking() { return _stopTrackFlag; }

	inline bool isTracking() { return _status == TR_STATUS_TRACKING || _status == TR_STATUS_STOPPING; }
	inline bool isStopped() { return _status == TR_STATUS_STOPPED; }

	inline bool isTrackerInitialized() { return _trackerInitFlag; }
	inline bool setTrackerInitiaized(bool init = true) { _trackerInitFlag = init; }

	inline TrackingStatus getStatus() { return _status; }
	inline void setStatus(TrackingStatus s) { _status = s; }

	inline bool isInitialized() { return _isInitialized; }

	inline FramePool* getInputPool() { return _inputPool; }
	inline FramePool* getOutputPool() { return _outputPool; }

	inline Sequence* getSequence() { return _model; }
	inline char* getFrameBuffer() { return _frameBuffer; }

private:
    Sequence* _model;

	FramePool* _inputPool;
	FramePool* _outputPool;

	char* _frameBuffer;

	bool _stopTrackFlag;

	bool _trackerInitFlag;


	TrackingStatus _status;
	bool _isInitialized;
};

#endif
